package jobs.resources.rewrite;

import javax.servlet.ServletContext;
import org.ocpsoft.rewrite.config.Configuration;
import org.ocpsoft.rewrite.config.ConfigurationBuilder;
import org.ocpsoft.rewrite.servlet.config.HttpConfigurationProvider;
import org.ocpsoft.rewrite.servlet.config.rule.Join;

/**
 * Clase que nos permite re-escribir las URL's de la aplicación
 *
 * @author Paul Tamayo
 */
public class URLRewriteProvider extends HttpConfigurationProvider {

    private final static String CATALOG_PATH = "/catalog/";
    private final static String REWRITE_CATALOG_PATH = "/administracion-de-";
    private final static String LIST_CATALOG_PATH = "/listado-de-catalogo";

    @Override
    public Configuration getConfiguration(ServletContext t) {
        ConfigurationBuilder builder = ConfigurationBuilder.begin();

        builder.addRule(Join.path("/inicio").to("/index.xhtml"));
        builder.addRule(Join.path(REWRITE_CATALOG_PATH+"nivel-de-instruccion").to(CATALOG_PATH + "attainments.xhtml"));
        builder.addRule(Join.path(REWRITE_CATALOG_PATH + "titulo").to(CATALOG_PATH + "degrees.xhtml"));
        builder.addRule(Join.path(REWRITE_CATALOG_PATH + "especificidad").to(CATALOG_PATH + "especificities.xhtml"));
        builder.addRule(Join.path(REWRITE_CATALOG_PATH + "grado").to(CATALOG_PATH + "grades.xhtml"));
        builder.addRule(Join.path(REWRITE_CATALOG_PATH + "posgrado").to(CATALOG_PATH + "graduates.xhtml"));
        builder.addRule(Join.path(REWRITE_CATALOG_PATH + "instituto").to(CATALOG_PATH + "institutions.xhtml"));
        builder.addRule(Join.path(REWRITE_CATALOG_PATH + "area-de-conocimiento").to(CATALOG_PATH + "knowledgeareas.xhtml"));
        builder.addRule(Join.path(LIST_CATALOG_PATH).to(CATALOG_PATH + "list.xhtml"));
        builder.addRule(Join.path(REWRITE_CATALOG_PATH + "grupo-ocupacional").to(CATALOG_PATH + "occupationalgroups.xhtml"));
        builder.addRule(Join.path(REWRITE_CATALOG_PATH + "relacion").to(CATALOG_PATH + "relationships.xhtml"));
        builder.addRule(Join.path(REWRITE_CATALOG_PATH + "rol").to(CATALOG_PATH + "roles.xhtml"));
        builder.addRule(Join.path(REWRITE_CATALOG_PATH + "ambito").to(CATALOG_PATH + "scopes.xhtml"));
        builder.addRule(Join.path(REWRITE_CATALOG_PATH + "pregrado").to(CATALOG_PATH + "undergraduates.xhtml"));
        builder.addRule(Join.path(REWRITE_CATALOG_PATH + "unidad").to(CATALOG_PATH + "units.xhtml"));
        builder.addRule(Join.path(REWRITE_CATALOG_PATH + "anios").to(CATALOG_PATH + "years.xhtml"));

        return builder;
    }

    @Override
    public int priority() {
        return 10;
    }
}
